24
Easy2Siksha
If everyone tries to enter rooms, lock doors, and then tries to grab the key to the next room,
it's a recipe for deadlock.
3. The Deadlock Scenario:
3.1 Processes Holding Locks:
Imagine four people in the house. Each person enters a room, locks the door behind them,
and holds the door handle (lock) while working inside. This is similar to processes acquiring
and holding locks on resources in a computer system.
In computer terms, a process holds a lock on a resource while it's using it. For example, a
prinng process holds a lock on the printer while prinng a document.
3.2 Processes Waing for Keys:
Now, each person wants to move to the next room to connue their tasks, but they need the
key to that room. However, the keys are held by others, who are also waing for someone
else to release the key to the room they need.
In computer systems, processes might need access to mulple resources to complete their
tasks. If each process is holding a resource and waing for another resource held by
someone else, a deadlock can occur.
4. The Stalemate:
4.1 Everyone Waing for Each Other:
In our house analogy, everyone is now stuck. Each person is holding a door handle (lock) to a
room and waing for the key to the next room, which is held by someone else. It's a
deadlock – no one can move forward because they're all waing for someone else to release
the key they need.
In a computer system, this state is problemac. Processes are halted, waing indenitely for
resources that are locked by others. The system becomes unresponsive, and tasks come to a
standsll.
Prevenng and Resolving Deadlocks:
Avoiding the Locked Doors Scenario:
To avoid or resolve deadlocks, strategies can be implemented:
5.1 Resource Allocaon Policies:
• Smart resource allocaon policies ensure that processes don't lock resources
indenitely. It's like having rules for who gets to hold a door handle for how long.
5.2 Deadlock Detecon and Recovery:
• Systems can detect deadlocks and take correcve acons, like breaking the cycle and
releasing resources. It's akin to someone in the house realizing the deadlock,
knocking on doors, and asking people to release the keys.